package icepick;

import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.view.View;
import java.util.LinkedHashMap;
import java.util.Map;

public class Icepick {
    public static final String ANDROID_PREFIX = "android.";
    private static final Map INJECTORS;
    public static final String JAVA_PREFIX = "java.";
    public static final String SUFFIX = "$$Icepick";
    private static final String TAG = "Icepick";
    private static boolean debug;

    static {
        debug = false;
        INJECTORS = new LinkedHashMap();
    }

    public Icepick() {

    }

    private static Injector getInjector(Class arg3) throws IllegalAccessException, InstantiationException {
        Injector v0_3;
        v0_3 = (Injector) Icepick.INJECTORS.get(arg3);
        if(v0_3 != null) {
            if(!Icepick.debug) {
                return v0_3;
            }

            Log.d("Icepick", "HIT: Cached in injector map.");
            return v0_3;
        }

        String v0_1 = arg3.getName();
        if(!v0_1.startsWith("android.") && !v0_1.startsWith("java.")) {
            try {
                v0_3 = (Injector) Class.forName(v0_1 + "$$Icepick").newInstance();
                if(Icepick.debug) {
                    Log.d("Icepick", "HIT: Class loaded injection class.");
                }
                else {
                }
            }
            catch(ClassNotFoundException v0_2) {
                if(Icepick.debug) {
                    Log.d("Icepick", "Not found. Trying superclass " + arg3.getSuperclass().getName());
                }

                v0_3 = Icepick.getInjector(arg3.getSuperclass());
            }

            Icepick.INJECTORS.put(arg3, v0_3);
            return v0_3;
        }

        if(Icepick.debug) {
            Log.d("Icepick", "MISS: Reached framework class. Abandoning search.");
        }

        return null;
    }

    public static void restoreInstanceState(Object arg1, Bundle arg2) {
        ((Injector.Object)Icepick.safeGet(arg1, new icepick.Injector.Object())).restore(arg1, arg2);
    }

    public static Parcelable restoreInstanceState(View arg1, Parcelable arg2) {
        return ((Injector.View)Icepick.safeGet(arg1, new icepick.Injector.View())).restore(arg1, arg2);
    }

    private static Injector safeGet(Object arg4, Injector arg5) {
        Injector v0_1;
        try {
            v0_1 = Icepick.getInjector(arg4.getClass());
            if(v0_1 != null) {
                return v0_1;
            }

            return arg5;
        }
        catch(Exception v0) {
            throw new RuntimeException("Unable to inject state for " + arg4, ((Throwable)v0));
        }

    }

    public static void saveInstanceState(Object arg1, Bundle arg2) {
        ((Injector.Object)Icepick.safeGet(arg1, new icepick.Injector.Object())).save(arg1, arg2);
    }

    public static Parcelable saveInstanceState(View arg1, Parcelable arg2) {
        return ((Injector.View)Icepick.safeGet(arg1, new icepick.Injector.View())).save(arg1, arg2);
    }

    public static void setDebug(boolean arg0) {
        Icepick.debug = arg0;
    }
}

